<template>
	<view class="container">
		<uni-section title="图" type="line">
			<image :src="'http://localhost:8090'+foods.icon" style="width: 100%;height: 140px;"></image>
			</swiper>
		</uni-section>

		<uni-section title="名称" sub-title="" type="line">
			<view class="">{{foods.name}}</view>
		</uni-section>
		<uni-section title="类别" sub-title="" type="line">
			<view class="">{{foods.type}}</view>
			</swiper>
		</uni-section>
		<uni-section title="价格" sub-title="" type="line">
			<view class="">{{foods.price}}</view>
			</swiper>
		</uni-section>
		<uni-section title="描述" sub-title="" type="line">
			<view class="">{{foods.description}}</view>
		</uni-section>
		<view class="plfb">
			<input type="text" placeholder="请输入评论内容" v-model="comm.comment" style="border: 2px solid #ccc;width: 80%;height: 35px; background-color: #fff;">
			<button type="default" @click="fabiao" style="width: 20%; height: 38px;border: 2px solid #ccc;line-height: 38px;">发表</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				foods: {},
				comm: {
					id: '',
					foodid: '',
					userid: uni.getStorageSync('formdata').id,
					comment: '',
					postdate: new Date()
				}
			}
		},
		methods: {
			fabiao() {
				if(uni.getStorageSync('formdata')){
					uni.request({
						url: 'http://localhost:8090/foodapp/comment/addone',
						method: 'POST',
						data: this.comm,
						success: res => {
							if (res.data.success) {
								uni.showToast({
									title: this.comm.comment,
									icon: 'none'
								});
							} else {
								uni.showToast({
									title: '失败',
									icon: 'none'
								});
							}
						}
					})
				}else{
					uni.showToast({
						title: '登录之后才能发表',
						icon: 'none'
					});
					setTimeout(()=>{
						uni.redirectTo({
							url: '../../my/login/login'
						});
					},200)
				}
			}
		},
		onLoad(e) {
			uni.request({
				url: 'http://localhost:8090/foodapp/food/findone',
				method: 'POST',
				data: {
					id: e.id
				},
				success: res => {
					this.foods = res.data.data
					if (res.data.success) {
						uni.showToast({
							title: '成功',
							icon: 'none'
						});
					} else {
						uni.showToast({
							title: '失败',
							icon: 'none'
						});
					}
				}
			}),
			this.comm.foodid=e.id
		}
		
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}

	.plfb {
		width: 100%;
		height: 35px;
		display: flex;
		position: fixed;
		bottom: 8px;
		right: -1px;
	}
</style>
